package com.teasale.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teasale.entity.Goods;
import com.teasale.service.GoodsService;
import com.teasale.mapper.GoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author water003
* @description 针对表【goods】的数据库操作Service实现
* @createDate 2023-06-06 19:05:29
*/
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods>
    implements GoodsService{

    @Autowired
    GoodsMapper goodsMapper;


    @Override
    public List<Goods> getall() {
        List<Goods> goods = goodsMapper.selectList(null);
        System.out.println(goods);

        return goods;
    }

    @Override
    public Goods getOneById(String goodsId) {

        QueryWrapper<Goods> wrapper = new QueryWrapper<>();
        wrapper.eq("goods_out_id",goodsId);
        return goodsMapper.selectOne(wrapper);
    }


    /**
     * 模糊搜索商品
     * @return 商品列表
     */
    @Override
    public List<Goods> findByLike(String name) {
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(name),"goods_name",name);
        List<Goods> goods = goodsMapper.selectList(queryWrapper);
        return goods;
    }
}




